//-----------------------------------------------------------------------
// <copyright file="UserService.cs" company="FetCo">
//     Copyright (c) FetCo. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using FetCo.Framework;
using ADESSA.Entities;
using ADESSA.Data;
    
namespace ADESSA.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class UserService
    {
        #region User

        public static void CreateUser(User user)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                userDAO.CreateUser(user);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessCreateUserException, ex);
            }
        }        

        public static void UpdateUser(User user)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                userDAO.UpdateUser(user);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessUpdateUserException, ex);
            }
        }        

        public static void DeleteUser(long userId)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                userDAO.DeleteUser(userId);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessDeleteUserException, ex);
            }
        }
        
        public static User GetUser(long userId)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                return userDAO.GetUser(userId);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetUserException, ex);
            }
        }                

        public static UserCollection GetUserList(UserColumns orderBy, OrderDirection orderDirection)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                return userDAO.GetUserList(orderBy, orderDirection);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetUserListException, ex);
            }
        }        

        public static UserCollection GetUserList(UserColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                return userDAO.GetUserList(orderBy, orderDirection, page, pageSize, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetUserListException, ex);
            }
        }        

	    public static UserCollection GetUserListByParam(object orderBy, OrderDirection orderDirection,string where)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                return userDAO.GetUserListByParam(orderBy, orderDirection,where);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetUserListException, ex);
            }
        }        

        public static UserCollection GetUserListByParam(object orderBy, OrderDirection orderDirection, int page, int pageSize,string Criteria, out int totalRecords)
        {            
            try
            {
                UserDAO userDAO = new UserDAO();
                return userDAO.GetUserListByParam(orderBy, orderDirection, page, pageSize,Criteria, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetUserListException, ex);
            }
        }        

        #endregion
    }
}